/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2011
 */

package com.tech15.core.dao;

import static cn.org.rapid_framework.util.ObjectUtils.isNotEmpty;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javacommon.base.BaseHibernateDao;

import org.springframework.stereotype.Repository;

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.page.PageRequest;

import com.tech15.core.model.ModuleAuth;
import com.tech15.core.vo.query.ModuleAuthQuery;

@Repository
public class ModuleAuthDao extends BaseHibernateDao<ModuleAuth,Long>{

	public Class getEntityClass() {
		return ModuleAuth.class;
	}
	
	public Page findPage(ModuleAuthQuery query) {
		String sql = "select t from ModuleAuth t where 1=1 "
			+ "/~ and t.mdid = '[mdid]' ~/"
			+ "/~ and t.authid = '[authid]' ~/"
			+ "/~ and t.authType = '[authType]' ~/"
			+ "/~ and t.did = '[did]' ~/"
			+ "/~ order by [sortColumns] ~/";

		return pageQuery(sql,query);
	}

	public List<ModuleAuth> findByMdid(Long mdid){
		String sql = "select t.mdid,t.maid,t.authid,t.auth_type as authType,t1.realname as name from sys_module_auth t left join sys_user t1 on t.authid=t1.userid where t.auth_type=1 and t.mdid="+mdid+" union "
					+"select t.mdid,t.maid,t.authid,t.auth_type as authType,t1.groupname as name from sys_module_auth t left join sys_group t1 on t.authid=t1.pgid where t.auth_type=2 and t.mdid="+mdid;
		Map map = new HashMap();
		map.put("mdid", "Long");
		map.put("maid", "Long");
		map.put("authid", "Long");
		map.put("authType", "String");
		map.put("name", "String");
		return findSqlAll(sql, map, ModuleAuth.class);
	}
	

}
